package cn.tedu.csmall.product.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Component;

/**
 * 切面类
 */
@Slf4j
@Aspect
@Component
public class TimerAspect {

    public TimerAspect(){
        log.debug("创建切面对象: TimerAspect");
    }

    @Around("execution(* cn.tedu.csmall.product.service.*.*(..))")
    public Object timer(ProceedingJoinPoint pjp) throws Throwable{

        log.debug("[{}]类型的对象调用了[{}]方法, 参数: [{}]",
                pjp.getTarget().getClass().getName(),
                pjp.getSignature().getName(),
                pjp.getArgs());

        long start = System.currentTimeMillis();
        Object result = pjp.proceed();
        long end = System.currentTimeMillis();
        log.debug("执行耗时: {}毫秒",end - start);
        return result;
    }
}
